#include<bits/stdc++.h>
using namespace std;
int T,n;
int a[200005];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        int ans=0;
        for(int i=n;i>=1;i--){
            for(int j=i-1;j>=1;j--){
                if(a[i]==a[j]&&(i-j)<=5){
                    ans+=a[i];
                }
            }
        }
        cout<<ans<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
